let titleWord = function (word) {
    return word[0].toUpperCase() + word.substr(1).toLowerCase();
}

let titleCase = function (str) {
    let words = str.toLowerCase().split(' ');
    return words.map(titleWord).join(' ');
}

console.log(titleCase("I'm a little tea pot"));
